from mysql_cli import *
class MysqlConnector():
    def __init__(self, config):
        self.config = config
        self.database = get_mysql_db(self.config)

    def create_table(self, sql):
        cur = self.database.cursor()
        cur.execute(sql)

    def insert(self):
        pass

    def update(self, table, change, condition):
        update_record(self.database, table, change, condition)

    def delelte(self, table, condition):
        delete_record(self.database, table, condition)

    def check_record(self, tb):
        check_record(self.database, tb)

    def find(self,table,query):
        cur = self.database.cursor()
        sql = ''' select * from {}  WHERE  {} '''.format(table,get_condition_sql(query))
        print('find', sql)
        cur.execute(sql)
        return cur.fetchall()

    def findone(self,table,query):
        cur = self.database.cursor()
        sql = ''' select * from {}  WHERE  {} '''.format(table,get_condition_sql(query))
        print('find', sql)
        cur.execute(sql)
        return cur.fetchone()

        